using Game.Core;
using Game.Main.Model;
using Game.Manager;
using UnityEngine;

namespace Game.Component
{
	public class ShoesItem : BaseItem
	{
		public Transform body;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			body = model.Find("Body");
			InitBody();
		}

		public void InitBody()
		{
			Transform transform = Singleton<AssetBundleManager>.Instance.characterResource.transform;
			ChangeSprite(body.Find("Left/Sprite"), transform.Find("Model/Body/LeftLeg/UpperLeg/LowerLeg/Shoe/" + base.itemData.shoesId));
			ChangeSprite(body.Find("Right/Sprite"), transform.Find("Model/Body/RightLeg/UpperLeg/LowerLeg/Shoe/" + base.itemData.shoesId));
		}

		private void ChangeSprite(Transform targetTrans, Transform spriteTrans)
		{
			if (spriteTrans == null)
			{
				targetTrans.GetComponent<SpriteRenderer>().sprite = null;
				return;
			}
			targetTrans.GetComponent<SpriteRenderer>().sprite = spriteTrans.GetComponent<SpriteRenderer>().sprite;
			targetTrans.localPosition = spriteTrans.localPosition;
		}

		protected override void CheckColls()
		{
			for (int i = 0; i < itemCompColls.Count; i++)
			{
				ItemComponentTrigger.Type type = itemCompColls[i].trigger.type;
				if ((type == ItemComponentTrigger.Type.LeftLeg || type == ItemComponentTrigger.Type.RightLeg) && itemCompColls[i].trigger.owner.itemData.scriptType == 1 && itemCompColls[i].trigger.owner.transform.position.y - base.transform.position.y > -0.2f && ((CharacterItem)itemCompColls[i].trigger.owner).ChangeShoes(base.itemData.shoesId))
				{
					GlobalEventSystem.Fire(new BaseEvent("game.remove_item", archiveData.index));
					return;
				}
			}
			base.CheckColls();
		}
	}
}
